<?php

use console\db\Migration;

/**
 * 创建用户动态数据相关信息表
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m180201_103000_t_user_account extends Migration {

    /**
     * {@inheritdoc}
     */
    public function up() {

        /**
         * 用户账户表
         * @table `user_account`.
         */
        $this->tableBuilder([
            'name' => 'user_account',
            'comment' => '用户账户表',
            'columns' => [
                'id' => $this->primaryKey(),
                'user_id' => $this->integer(11)->notNull()->defaultValue(0)->comment('用户ID'),
                'type' => $this->tinyint(1)->unsigned()->notNull()->defaultValue(0)->comment('货币类型'),
                'current' => $this->integer(11)->notNull()->defaultValue(0)->comment('当前账户积分'),
                'in' => $this->integer(11)->notNull()->defaultValue(0)->comment('总收入'),
                'out' => $this->integer(11)->notNull()->defaultValue(0)->comment('总支出'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(0)->comment('账户状态'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
            ],
            'index' => [
                [
                    'columns' => 'user_id',
                ],
                [
                    'columns' => 'type',
                ]
            ]
        ]);

        /**
         * 用户账户异常信息表
         * @table `user_account_abnorm`.
         */
        $this->tableBuilder([
            'name' => 'user_account_abnorm',
            'comment' => '用户账户异常信息表',
            'columns' => [
                'id' => $this->primaryKey(),
                'account_id' => $this->integer(11)->notNull()->defaultValue(0)->comment('账户ID'),
                'user_id' => $this->integer(11)->notNull()->defaultValue(0)->comment('用户ID'),
                'type' => $this->tinyint(1)->unsigned()->notNull()->defaultValue(0)->comment('账户类型'),
                'mark' => $this->string(255)->notNull()->defaultValue('')->comment('异常原因'),
                'data' => $this->text()->comment('异常时账户信息'),
                'admin_id' => $this->integer(11)->notNull()->defaultValue(0)->comment('操作员ID'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(0)->comment('异常状态'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
            ],
            'index' => [
                [
                    'columns' => 'account_id',
                ],
                [
                    'columns' => 'user_id',
                ],
                [
                    'columns' => 'type',
                ]
            ]
        ]);
    }

    /**
     * {@inheritdoc}
     */
    public function down() {
        $this->dropTable('{{%user_account_abnorm}}');
        $this->dropTable('{{%user_account}}');
    }

}
